package com.group10.util;


import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;

public class CreateMessage {
    public static MimeMessage createMimeMessage(Session session, String fromAccount, String toAccount,String subject,String TEXT)
            throws Exception {
        // 1.创建邮件对象
        MimeMessage message = new MimeMessage(session);
        // 2.设置发件⼈
        message.setFrom(new InternetAddress(fromAccount, "民风民俗文化分享平台", "UTF-8"));

        // 3.设置收件⼈
        message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(toAccount , "UTF-8"));

        // 7.设置邮件主题
        message.setSubject(subject,"UTF-8");

        // 8.设置邮件正⽂内容，指定格式为HTML格式
        message.setContent(TEXT, "text/html;charset=UTF-8");
        // 9.设置显示发件时间
        message.setSentDate(new Date());

        // 10.保存设置
        message.saveChanges();

        return message;
    }
}
